package com.bid.base.common.util.codec;

import com.bid.base.common.util.RandomGenerator;

/**
 * <strong>Description : </strong> <br>
 * <p>
 * <strong>北京正源德标科技信息有限责任公司</strong> <br>
 * </p>
 * <br>
 *
 * @author : zhaots
 * @date Date : 2020年12月07日 18:22
 * 修改人 修改日期 修改描述<br>
 * -------------------------------------------<br>
 * <br>
 * <br>
 */
public class Base64
{
	
	public static String encodeWrapper(byte[] data)
	  {
	    if (data == null) return null;
	    return RandomGenerator.randomString(2)+new String(org.bouncycastle.util.encoders.Base64.encode(data));
	  }
	
  public static String encode(byte[] data)
  {
    if (data == null) return null;
    return new String(org.bouncycastle.util.encoders.Base64.encode(data));
  }

  public static byte[] decode(String data)
    throws CodecException
  {
    if (data == null) return null;
    try
    {
      return org.bouncycastle.util.encoders.Base64.decode(data.getBytes());
    }
    catch (RuntimeException e) {
      throw new CodecException(e.getMessage(), e);
    }
  }

  public static void main(String[] args) throws CodecException
  {
    System.out.println(encode("a和法国和a".getBytes()));
    System.out.println(new String(decode("YeWSjOazleWbveWSjGE=")));
  }
}